package cn.itcast.dagger2demo;

import java.util.concurrent.TimeUnit;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

/**
 * Created by Administrator on 2016/8/3.
 */
@Module
public class ApiModule {

    public static final String BASE_ULL = "http://192.168.209.1:8080/p2p/";

    @Provides
    @Singleton
    OkHttpClient provideOkHttpClient() {

        OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(60 * 1000, TimeUnit.MICROSECONDS)
                .readTimeout(60 * 1000, TimeUnit.MICROSECONDS).build();
        return okHttpClient;
    }

    @Provides
    @Singleton
    Retrofit provideRetrofit(OkHttpClient okHttpClient) {

        Retrofit retrofit = new Retrofit.Builder()
                .client(okHttpClient)
                .baseUrl(BASE_ULL).build();
        return retrofit;
    }

    @Provides
    @Singleton
    public User provideUser() {

        return new User("User from ApiModule");
    }

}
